<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value=" ${pageContext.request.contextPath}" />
<html>
<head>
<title>整改措施管理</title>
<script type="text/javascript">

var $grid;
var grid;
	var $classesSelector;
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			url : "${ctx}/fnd/zgCs/dataGrid?businessKey=${param.businessKey}",
			fitColumns : true,
			frozenColumns : [ [] ],
			nowrap:false,
			columns : [ [ {
				field : 'ck',
				checkbox : true
			} ,{
				field : 'zgcs',
				title : '整改措施',
				width :　220,
				sortable : true
			},{
				field : 'zgmb',
				title : '整改目标',
				width :　220,
				sortable : true
			},{
				field : 'zgPlanTime',
				title : '整改计划完成时间 ',
				width :　100,
				sortable : true
			},{
				field : 'zgActiveTime',
				title : '整改实际完成时间 ',
				width :　100,
				sortable : true
			},{
				field : 'createTime',
				title : '创建时间 ',
				width :　100,
				sortable : true
			}, {
				field : 'attachmentMaster.id',
				title : '附件',
				sortable : true,
				width : 120,
				formatter : function(value, row, index) {
					if(row.attachCnt==0){
						return "<button id=\"attach\" type=\"button\" class=\"btn btn-default  \" onclick=\"fn_attachClick('"+value+"')\"><span class=\"glyphicon glyphicon-pencil\"></span> 附件</button>";
					}else{
						return "<button id=\"attach\" type=\"button\" class=\"btn btn-primary  \" onclick=\"fn_attachClick('"+value+"')\"><span class=\"glyphicon glyphicon-pencil\"></span> 附件</button>";
					}
				}  
			}
      ] ],
			onDblClickRow : function(index, rowData) {
				$.isFunction(fn_edit) && fn_edit.call(this, rowData);
			}
		}));
		
	 
		
		$grid.datagrid('enableFilter', [ buildDGFilterYesOrNoFieldOptions($grid, 'enable') ]);
	 
		
	 $("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load',{
			 	"auditProDtl" :'${param.businessKey}',
			 	"status":"1"
			});
	     	$("#dlg-btn").show();
			$("#dlg").dialog("open").dialog("setTitle", "新增整改措施");
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (!rowData) {
				showInfo("您未选中行，无法编辑");
			} else {
				fn_edit(rowData);
			}
		});
		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/fnd/zgCs/multiDelete");
		});
		 
		$("#excelExport")
		.click(
				function() {
					var url = "${ctx}/fnd/zgCs/excelExport?"
							+ $
									.param($grid.datagrid('options').queryParams);
					if ($grid.datagrid("options").filterRules) {
						url += "&filterRules="
								+ JSON
										.stringify($grid
												.datagrid("options").filterRules);
					}
					window.parent.location.href = url;
				});
	});
	 
	 function fn_edit(rowData) {
		 var isEdit="${isEdit}";
			if(isEdit=="1"){
				$("#dlg").dialog("open").dialog("setTitle", "编辑整改措施");
				$("#dlg-btn").show();
			}else{
				$("#dlg").dialog("open").dialog("setTitle", "查看整改措施");
				$("#dlg-btn").hide();
			}
			
			

			$("#fm").form("clear");
			$("#fm").form("load", $.extend(rowData, {			
				"auditProDtl" :rowData.auditProDtl.id			 		
			}));
			$("#auditFinding").html(rowData.auditProDtl.auditFinding);
			$("#auditSuggestion").html(rowData.auditProDtl.auditSuggestion);
	}
	 
	 
	//-----------------------------附件-----------------------------------------------//		
		function fn_attachClick(id){		  
			grid&&grid.datagrid('loadData',{total:0,rows:[]});
			grid = $("#grid_attach").datagrid({
				title : "附件",
				fitColumns : true,
				//method : "get",
				singleSelect : true,
				pagination : true,
				url : "${ctx}/basic/attachment/dataGrid/"+id+"?attachmentType="+encodeURI("整改方案")
			});
			
			
			var isEdit="${isEdit}";
			if(isEdit=="1"){
				$("#dlg_attach").dialog("open").dialog("setTitle", "编辑附件");
				$('#uploader').show();
				initWebuploaderWithAttachType(id); 
			}else{
				$("#dlg_attach").dialog("open").dialog("setTitle", "查看附件");
				$('#uploader').hide();
			} 
		}
		
		function fn_attach_formatter(value, row, index) {
			var rowData = $grid.datagrid('getSelected');
			var button="";
			var isEdit="${isEdit}";
			if(isEdit=="1"){
			 button=fmt_attach(value, row, index);
			}else{
				 button=fmt_attachView(value, row, index);
			}
			 return button;
		}
		
		function initWebuploaderWithAttachType(id){
			uploader&&uploader.destroy();
		    initWebuploader(id);
		    uploader.off("fileQueued");
		    uploader.on('fileQueued', function (file) {
				var attachmentType="整改方案";
	        	if(!attachmentType){
	        		 alert("请选择上传类型！！");
	        		  var $li = $('.item');
		        	 $li.fadeOut();
		        	 uploader.stop();
	        		 uploader.reset();
	        		 return false;
	        	}
	        	
	                 var $li = $('#'+file.id );
	                  $percent = $li.find('.info');
	                 if (!$percent.length) {
	                     $("#thelist").append('<div id="'+file.id+'" class="item">' +
	                      '<h4 class="info">' + file.name + '</h4>' +
	                      '<p class="state">等待上传...</p>' +
	                     ' <span id="iid"></span><span id="all"></span></div>');
	                     _queue.push(file);
	                 }
	                 else {
	                     var $lii = $('#'+file.id );//修改已上传的
	                     $lii.fadeIn();
	                     $lii.html('<div id="'+file.id+'" class="item">' +
	                    '<h4 class="info">' + file.name + '</h4>' +
	                    '<p class="state">等待上传...</p>' +
	                   '<span id="iid"></span><span id="all"></span></div>');

	                 }
	         });

		    uploader.on('uploadBeforeSend', function (file, data) {
		    	var attachmentType="整改方案";
	        	if(!attachmentType){
	        		 alert("系统出错，请及时联系系统管理员！");
	        	}else{
	        		data.attachmentType=encodeURI(attachmentType);
	        	}
            });
		    
		    uploader.off("uploadFinished");
		    uploader.on("uploadFinished", function () {
	             initWebuploaderWithAttachType(id);
	         });
		    
		}
</script>
</head>



<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="row">
		<div class="col-md-12">
			<c:if test="${isEdit==1}"> 
		  		<c:if test="${not empty param.taskId}">
					<button id="add" type="button" class="btn btn-primary">
						<span class="glyphicon glyphicon-plus"></span> 新增
					</button>
					<button id="delete" type="button" class="btn btn-danger">
						<span class="glyphicon glyphicon-minus"></span> 删除
					</button>	  
			 	</c:if>  
			 </c:if>
			 <button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑 / 查看
			</button>
			<span style="float:right;padding:8px 0 0 0;color:red;">双击行或点击“编辑 / 查看”按钮，可打开窗口查看详细数据</span>	
		</div>
	</div>

		<div id="dlg" class="easyui-dialog" style="width: 900px; height:520px; padding: 10px 20px"
			data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
			<form id="fm" method="post">
				<input type="hidden" name="id" /> 
				<input  type="hidden" name="auditProDtl" />
				<input type="hidden" name="status" /> 
				
			    <table id="tbl">
			    	<tr>
						<td colspan="2"><label>整改发现问题:</label></td>
					</tr>
					<tr>
						<td colspan="4"><div id="auditFinding" style="width: 800px;overflow: auto;border:1px solid #000;padding: 10px;" >${auditFinding}</div></td>
					</tr>
			    	<tr>
						<td colspan="2"><label>整改建议:</label></td>
					</tr>
			    	<tr>
						<td colspan="4"><div id="auditSuggestion"  style="width: 800px;overflow: auto;border:1px solid #000;padding: 10px;" >${auditSuggestion}</div></td>
					</tr>
					<tr>
						<td colspan="2"><label>整改措施:</label></td>
						<td colspan="2"><label>整改目标:</label></td>
					</tr>
					<tr>
						<td colspan="2"><input name="zgcs" class="easyui-textbox" data-options="multiline:true,width:410,height:100,required: true,validType:['length[0,800]']"  ></td>
						<td colspan="2"><input name="zgmb" class="easyui-textbox" data-options="multiline:true,width:410,height:100,required: true,validType:['length[0,800]']"  ></td>
					</tr>
					<tr>
						<td><label>整改计划完成时间:</label></td>
						<td><input id="zgPlanTime" name="zgPlanTime" class="easyui-datebox" data-options="required: true"></td>
						<td></td>
						<td></td>
					</tr>
				</table>
			</form>
			<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary"
					onclick="formSave('#fm', '#grid', '#dlg', '${ctx}/fnd/zgCs/update');">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</div>
		
		
	 
		<div id="dlg_attach" class="easyui-dialog"
			style=" padding: 10px 20px"
			data-options="resizable:true,modal:true,closed:true,fit:true">
			<div id="tt_attach" class="row">
				<div class="col-md-12">
					<!-- <input id="attachmentType"  class="easyui-validatebox" data-options="" > -->
				
				</div>
			</div>
			<div  class="easyui-layout" data-options="fit:true">   
				<div data-options="region:'center',border:false">
					<table id="grid_attach" data-options="fit:true,toolbar: '#tt_attach'">
						<thead>
							<tr>
								<th field="id" hidden="true"></th>
								<th field="attachmentType" width="160">附件分类</th>
								<th field="fileName" width="160">文件名称</th>
								<th field="fileSize" width="60">大小</th>
								<th field="uploadTime" width="60">上传时间</th>
								<th field="operate" width="60" data-options="formatter:fn_attach_formatter"  >操作</th>
							</tr>
						</thead>
					</table>
				</div>
				<div data-options="region:'south'" style="height:150px">
					<div id="uploader" class="wu-example">
					    <div class="btns">
					        <div id="picker">选择文件</div>
					    </div>
					     <!--用来存放文件信息-->
					    <div id="thelist" class="uploader-list"></div>
					</div>
				</div>
			</div>
		</div>

</body>
</html>
 


 